package com.aipodcast.webbackend.controller;

import com.aipodcast.webbackend.config.model.ApiResponse;
import com.aipodcast.webbackend.entity.Courses;
import com.aipodcast.webbackend.entity.vo.CoursePageVo;
import com.aipodcast.webbackend.entity.vo.CourseVo;
import com.aipodcast.webbackend.service.ICoursesService;
import com.aipodcast.webbackend.utils.ApiResponseUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 课程表 前端控制器
 * </p>
 *
 * @author baomidou
 * @since 2025-09-22
 */
@RestController
@RequestMapping("/courses")
public class CoursesController {

    @Resource
    private ICoursesService coursesService;


    @GetMapping("/getCourseList")
    public ApiResponse<CoursePageVo> getCourseList(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) {
        return ApiResponseUtils.success(coursesService.getCourseListPublic(pageNum, pageSize));
    }

    @GetMapping("/{id}")
    public ApiResponse<CourseVo> getCourse(@PathVariable String id) {
        Courses course = coursesService.getCourse(id);
        return ApiResponseUtils.success(convert(course));
    }

    private CourseVo convert(Courses courses) {
        CourseVo courseVo = new CourseVo();
        BeanUtils.copyProperties(courses, courseVo);
        return courseVo;
    }
}
